<!--
 * @Author: zhangxiangsheng 1026583651@qq.com
 * @Date: 2024-06-18 13:57:45
 * @LastEditors: zhangxiangsheng 1026583651@qq.com
 * @LastEditTime: 2024-06-25 08:54:35
 * @FilePath: \appGly\pages\Station\StationHD\StationedtHDtype.vue
 * @Description: 
 * 
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. 
-->
<template>
  <view>
    <u-navbar title="收费模式"></u-navbar>
    <formz ref="formz" v-if="showform" :inputs="inputs" :data="data"></formz>
    <fixedbtn>
      <u-button type="primary" @click="save" :loading="loading">
        {{ $z.$t("确认修改") }}
      </u-button>
    </fixedbtn>
  </view>
</template>

<script>
  import json from "@/pages/ChargeCar/indexjson.js";
  export default {
    data() {
      return {
        inputs: json.ChargeCartypes,
        loading: false,
        data: {},
        showform: false,
      };
    },
    onLoad(query) {
      this.query = query;
      this.init();
    },
    methods: {
      async init() {
        let StationHD = await this.$z.request("/StationHD", {
          id: this.query.id,
        });
        StationHD = StationHD.length == 1 ? StationHD[0] : {};
        let StationCar = await this.$z.request("/StationCar", {
          id: this.query.id,
        });
        StationCar = StationCar.length == 1 ? StationCar[0] : {};

        this.data = {
          ...StationHD,
          ...StationCar,
        };
        this.showform = true;
        // console.log(this.data, " this.data");
      },
      async save() {
        let data = await this.$refs.formz.validate();

        this.loading = true;
        let par = await this.$z.request("/StationedtHD", data);
        if (data.type == "12" || data.type == "14") {
          let formdatakeys = [
            ["jsjsh1", "jsjsm1", "jsjeh1", "jsjem1"],
            ["jsjsh2", "jsjsm2", "jsjeh2", "jsjem2"],
            ["jsjsh3", "jsjsm3", "jsjeh3", "jsjem3"],
            ["fsjsh1", "fsjsm1", "fsjeh1", "fsjem1"],
            ["fsjsh2", "fsjsm2", "fsjeh2", "fsjem2"],
            ["fsjsh3", "fsjsm3", "fsjeh3", "fsjem3"],
            ["psjsh1", "psjsm1", "psjeh1", "psjem1"],
            ["psjsh2", "psjsm2", "psjeh2", "psjem2"],
            ["psjsh3", "psjsm3", "psjeh3", "psjem3"],
            ["gsjsh1", "gsjsm1", "gsjeh1", "gsjem1"],
            ["gsjsh2", "gsjsm2", "gsjeh2", "gsjem2"],
            ["gsjsh3", "gsjsm3", "gsjeh3", "gsjem3"],
          ];
          formdatakeys = formdatakeys.flat();
          let rdata = { ...data };
          //
          formdatakeys.forEach((e) => {
            rdata[e] = data[e] || "0";
          });
          await this.$z.request("/StationCardfedt", rdata);
        }
        this.loading = false;
        this.$z.back();
      },
    },
  };
</script>

<style></style>
